import 'package:flutter/material.dart';

/*
* 自定义appbar
* */
class MyAppBar {
  /// appbar的高度
  static double appHeight(BuildContext context) {
    return build(context, title: "").preferredSize.height;
  }

  /// 自定义appbar
  static PreferredSizeWidget build(
    BuildContext context, {
    required String? title,
    Color? titleColor,
    Widget? customChild,
    Widget? leading,
    double titleSpacing = NavigationToolbar.kMiddleSpacing,
    bool canBack = true,
    List<Widget>? actions,
    PreferredSizeWidget? bottom,
    double? elevation,
    Color? backgroundColor,
    double? height,
    Widget? flexibleSpace,
    TextStyle? titleStyle,
    IconThemeData? iconTheme,
    bool? centerTitle,
  }) {
    return AppBar(
      leading: leading,
      centerTitle: centerTitle ?? true,
      titleSpacing: titleSpacing,
      title: title == null
          ? customChild
          : Text(
              title,
              style: titleStyle,
            ),
      automaticallyImplyLeading: canBack,
      actions: actions,
      bottom: bottom,
      backgroundColor: backgroundColor,
      elevation: elevation,
      flexibleSpace: flexibleSpace,
      iconTheme: iconTheme,
    );
  }
}
